package org.lql.algo.codecrush.hot100.array;

import java.util.Arrays;

/**
 * @author: liangqinglong
 * @date: 2025-08-30 22:08
 * @description: 189. 轮转数组 <a href="https://leetcode.cn/problems/rotate-array/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class Rotate {

	public void rotate(int[] nums, int k) {
		int n = nums.length;
		k = k % n;
		int[] ans = new int[n];
		for (int i = 0; i < n; i++) {
			ans[(i + k) % n] = nums[i];
		}
		System.arraycopy(ans, 0, nums, 0, n);
	}

	public static void main(String[] args) {
		int[] nums = {1, 2, 3, 4, 5, 6, 7};
		int k = 3;
		Rotate rotate = new Rotate();
		System.out.println(Arrays.toString(nums));
		rotate.rotate(nums, k);
		System.out.println(Arrays.toString(nums));
	}
}
